package com.zxcl.strategy.factory;

import com.zxcl.strategy.LoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述: [策略工厂]
 * 作者: zxcl
 */
@Component
public class LoginStrategyFactory  {

    /**
     * 它会把IOC容器里面实现了LoginStrategy接口的对象注入到loginStrategyMap，并把对象的name作为key
     */
    @Autowired
    private Map<String, LoginStrategy> loginStrategyMap = new HashMap<>();

    /**
     * 根据类型返回不同的策略
     *
     * @param loginType
     * @return
     */
    public LoginStrategy getInstance(String loginType) {
        return loginStrategyMap.get(loginType);
    }

}
